#include<QtGui/QGridLayout>
#include<QtGui/QPushButton>
#include<QtGui/QCheckBox>

#include"titleselectdialog.h"

TitleSelectDialog::TitleSelectDialog(QWidget *parent)
    :QDialog(parent)
{
    Name = new QCheckBox(tr("Name"),this);
    Artist = new QCheckBox(tr("Artist"),this);
    Album = new QCheckBox(tr("Album"),this);
    Year = new QCheckBox(tr("Year"),this);
    Genre = new QCheckBox(tr("Genre"),this);
    Time = new QCheckBox(tr("Time"),this);
    Location = new QCheckBox(tr("Disk Location"));

    Button = new QPushButton(tr("OK"),this);
    Button->setEnabled(false);
    ButtonNo = new QPushButton(tr("Cancel"),this);
    ButtonNo->setEnabled(true);

    setWindowTitle("titles in song list table");
    Layout = new QGridLayout(this);
    Layout->addWidget(Name,0,0);
    Layout->addWidget(Artist,0,1);
    Layout->addWidget(Album,0,2);
    Layout->addWidget(Year,1,0);
    Layout->addWidget(Genre,1,1);
    Layout->addWidget(Time,1,2);
    Layout->addWidget(Location,2,0);

    Layout->addWidget(Button,0,3);
    Layout->addWidget(ButtonNo,1,3);
    setLayout(Layout);



    setFixedWidth(sizeHint().width());
    setFixedHeight(sizeHint().height());

    connect(Name,SIGNAL(clicked()),this,SLOT(enableOkButton()));
    connect(Artist,SIGNAL(clicked()),this,SLOT(enableOkButton()));
    connect(Album,SIGNAL(clicked()),this,SLOT(enableOkButton()));
    connect(Year,SIGNAL(clicked()),this,SLOT(enableOkButton()));
    connect(Time,SIGNAL(clicked()),this,SLOT(enableOkButton()));
    connect(Genre,SIGNAL(clicked()),this,SLOT(enableOkButton()));
    connect(Location,SIGNAL(clicked()),this,SLOT(enableOkButton()));


    connect(Button,SIGNAL(clicked()),this,SLOT(buttonOk()));
    connect(ButtonNo,SIGNAL(clicked()),this,SLOT(buttonNo()));

}

void TitleSelectDialog::buttonOk()
{
    Tags.clear();
    if(Name->checkState() == Qt::Checked)Tags<<tr("Name");
    if(Artist->checkState() == Qt::Checked)Tags<<tr("Artist");
    if(Album->checkState() == Qt::Checked)Tags<<tr("Album");
    if(Year->checkState() == Qt::Checked)Tags<<tr("Year");
    if(Genre->checkState() == Qt::Checked)Tags<<tr("Genre");
    if(Time->checkState() == Qt::Checked)Tags<<tr("Time");
    if(Location->checkState() == Qt::Checked)Tags<<tr("Location");
    emit titleChanged(Tags);
    this->destroy();
}

void TitleSelectDialog::enableOkButton()
{
    Button->setEnabled(true);
}

void TitleSelectDialog::buttonNo()
{
    this->destroy(true,true);
}

